class PartsController < ApplicationController
  before_action :set_menu

  def new
    @part = Part.new
  	@part_styles = PartStyle.all
  end

  def create
    @part = Part.new post_params
    if @part.save
      redirect_to part_style_path(:id =>@part.part_style.id)
    else
      render :action => 'new'
    end
  end

  def destroy
    @part = Part.find params[:id]
    @part.destroy
    redirect_to part_style_path(:id =>@part.part_style.id)
  end


  def post_params
    params.require(:part).permit(*%w(part_style_id name code purchase_price sales_price unit car_mo brand origin note))
  end

  private
  def set_menu
    @mainmenu = :part
  end
end
